#include "coin.h"

//Coin::Coin(QWidget *parent) : QPushButton(parent)
//{

//}

Coin::Coin(QString Img)
{
    QPixmap pix;
    pix.load(Img);
    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{border:0px}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));

    this->timerturn = new QTimer(this);
    this->is_win=false;

    connect(this->timerturn,&QTimer::timeout,[=](){
        QString coinPath;
        if(m_flag==true)
        {
            coinPath = QString(":/coin/res/Coin000%1.png").arg(this->min++);
        }
        else
        {
            coinPath = QString(":/coin/res/Coin000%1.png").arg(this->max--);
        }
        QPixmap pix1;
        pix1.load(coinPath);
        this->setFixedSize(pix1.width(),pix1.height());
        this->setStyleSheet("QPushButton{border:0px}");
        this->setIcon(pix1);
        this->setIconSize(QSize(pix1.width(),pix1.height()));
        if(min>max)
        {
            min=1;
            max=8;
            m_flag=!m_flag;
            timerturn->stop();
        }
    });
}

void Coin::changeCoin(void)
{
    timerturn->start(30);
}

void Coin::mousePressEvent(QMouseEvent*e)
{
    if(this->is_win==true)
        return;
    else
        QPushButton::mousePressEvent(e);
}
